<?php
class daka_class_testModel extends RelationModel
{
    public $_validate = array(
        array('title','require','题目不能为空'),
        array('answer','require','答案不能为空'),
        array('content[1]','require','选项不能为空'),
    );

    protected $_link = array(
        //关联角色
        'class_list' => array(
            'mapping_type' => BELONGS_TO,
            'class_name' => 'daka_class_list',
            'foreign_key' => 'class_list_id',
        )
    );
	
	protected function _before_delete($options) {
		$this->deletedata($options);
	}
	protected function _after_insert($data, $options) {
		$this->deletedata($options);
    }
	protected function _after_update($data, $options) {
		$this->deletedata($options);
    }
	
	public function deletedata($options){
		$id = $options['where']['id'];
		//找出这个id 的所属 class_list_id
		$data = $this->where(array('id'=>$id))->find();
		if($data){
			$cache_name = 'test/'.$data['class_list_id'];
			F($cache_name, NULL);
			$cache_name = 'class/'.$data['class_list_id'];
			F($cache_name, NULL);
		}
		
	 }
}